package com.yeban.javase.day09.test;

import java.util.LinkedList;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/18
 *
 * 练习1：用LinkedList集合，模拟队列操作(存入的元素是Person对象)
 * 练习2：用LinkedList集合，模拟堆栈操作(存入的元素是Person对象)
 *
 */
public class test04 {

    public static void main(String[] args) {

        // 模拟队列操作
        LinkedList<Person> list1 = new LinkedList<>();
        System.out.println("---------- 模拟队列操作 ----------");
        // 先进
        System.out.println("元素进入");
        list1.addLast(new Person("张三",18));
        System.out.println("添加了Person1：" + list1);
        list1.addLast(new Person("李四",19));
        System.out.println("添加了Person2：" + list1);
        list1.addLast(new Person("王五",19));
        System.out.println("添加了Person3：" + list1);
        // 先出
        System.out.println("\n元素退出");
        list1.removeFirst();
        System.out.println("移除了Person1：" + list1);
        list1.removeFirst();
        System.out.println("移除了Person2：" + list1);
        list1.removeFirst();
        System.out.println("移除了Person3：" + list1);


        // 模拟堆栈操作
        LinkedList<Person> list2 = new LinkedList<>();
        System.out.println("\n---------- 模拟堆栈操作 ----------");
        // 先进
        System.out.println("元素入栈");
        list2.push(new Person("张三",18));
        System.out.println("添加了Person1：" + list2);
        list2.push(new Person("李四",19));
        System.out.println("添加了Person2：" + list2);
        list2.push(new Person("王五",19));
        System.out.println("添加了Person3：" + list2);
        // 后出
        System.out.println("\n元素弹栈");
        list2.pop();
        System.out.println("移除了Person1：" + list2);
        list2.pop();
        System.out.println("移除了Person2：" + list2);
        list2.pop();
        System.out.println("移除了Person3：" + list2);



    }
}

class Person1 {
    private String name;
    private int age;

    public Person1() {
    }

    public Person1(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Person1{name = " + name + ", age = " + age + "}";
    }
}
